#ifndef CONFIGAPI_HPP
#define CONFIGAPI_HPP
#include <stdint.h>
#include <stdbool.h>
#include "keyvalue.hpp"
#include "variable.hpp"
#include "app_config.h"
///> 配置文件的API,通过底层库进行读写
using namespace configraion;
///>各种变量名
#define FACTORYCONFIG_DISK							file::DISK_1
#define CONFIG_DISK											file::DISK_2
#define CONFIG_COMCONFIG_NAME						"comcfg"
#define CONFIG_LCDCUSTOMCONFIG_NAME			        "lcdcustomcfg"
#define CONFIG_SWITCHCUSTOMCONFIG_NAME	            "swtcustomcfg"
#define CONFIG_PRODUCTINFOR_NAME				    "productcfg"
#define CONFIG_METERCALI_NAME						"metercali"
#define CONFIG_SECURITY_NAME						"security"

///> 各种结构体变量的模板
#define KEYDEMO_COMCONFIG																				\
{																																\
	{1, 2, (uint32_t)&((ComConfigTPDF *)0)->usAddr},							\
	{2, 2, (uint32_t)&((ComConfigTPDF *)0)->usBaud},							\
}

#define KEYDEMO_SECURITYONFIG																				\
{																																		\
	{1, 2, (uint32_t)&((SecurityConfigTPDF *)0)->usNetChangeEnable},	\
	{2, 2, (uint32_t)&((SecurityConfigTPDF *)0)->usNetControlEnable},	\
	{3, 2, (uint32_t)&((SecurityConfigTPDF *)0)->usLanguage},					\
	{4, 2, (uint32_t)&((SecurityConfigTPDF *)0)->usPasswordEnable},		\
	{5,	8, (uint32_t)&((SecurityConfigTPDF *)0)->ucPassword},					\
}

#define KEYDEMO_LCDCUSTOMCONFIG																							\
{																																						\
	{1,  	2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usLongDelayCurrent},			\
	{2,  	2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usLongDelayTime},				\
	{3,  	2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usShortDelayCurrent},		\
	{4,  	2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usShortDelayTime},				\
	{5,  	2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usShortCircuitCurrent},	\
	{6,  	2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usEarthCurrent},					\
	{7,  	2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usEarthTime},						\
	{8,  	2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usNCurrent},							\
	{9,  	2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usUnbalanceRated},				\
	{10,  2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usUnbalanceTime},				\
	{11,  2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usBlockCurrent},					\
	{12,  2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usBlockTime},						\
	{13,  2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usLongDelayEnable},			\
	{14,  2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usShortDelayEnable},			\
	{15,  2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usShortCircuitEnable},		\
	{16,  2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usNEnable},							\
	{17,  2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usEarthEnable},					\
	{18,  2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usUnbalanceEnable},			\
	{19,  2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usBlockEnable},					\
	{20,  2,  (uint32_t)&((LcdCustomConfigTPDF *)0)->usFrequnce},							\
}

#define KEYDEMO_PRODUCTINFOR																			\
{																																	\
	{1, 1,  (uint32_t)&((ProductInforTPDF *)0)->ucManufactoryId},		\
	{2, 1,  (uint32_t)&((ProductInforTPDF *)0)->ucClass},						\
	{3, 1,  (uint32_t)&((ProductInforTPDF *)0)->ucSerial},					\
	{4, 1,  (uint32_t)&((ProductInforTPDF *)0)->ucPriSerial},				\
	{5,	2,  (uint32_t)&((ProductInforTPDF *)0)->ucHardwareSerial},	\
	{6, 24, (uint32_t)&((ProductInforTPDF *)0)->ucSN},							\
	{7, 2,  (uint32_t)&((ProductInforTPDF *)0)->usCurrent},					\
	{8, 2, 	(uint32_t)&((ProductInforTPDF *)0)->usStructCurrent},		\
	{9,2, 	(uint32_t)&((ProductInforTPDF *)0)->usAttribute},				\
	{10,16, (uint32_t)&((ProductInforTPDF *)0)->ucSoftDescription},	\
}

const keyvalue::KeyDemoTPDF mKeyDemoComConfig[] = KEYDEMO_COMCONFIG;
const keyvalue::KeyDemoTPDF mKeyDemoLcdCustomConfig[] = KEYDEMO_LCDCUSTOMCONFIG;
const keyvalue::KeyDemoTPDF mKeyDemoProductInfor[] = KEYDEMO_PRODUCTINFOR;
const keyvalue::KeyDemoTPDF mKeyDemoSecurity[] = KEYDEMO_SECURITYONFIG;  ///> 安全配置

typedef struct
{
	uint32_t uiIaL;		///<A相小通道增益
	uint32_t uiIbL;		///<B相小通道增益
	uint32_t uiIcL;		///<C相小通道增益
	uint32_t uiIaH;		///<A相大通道增益
	uint32_t uiIbH;		///<B相大通道增益
	uint32_t uiIcH;		///<C相大通道增益
	uint32_t uiIn;		///<N相通道增益
	uint32_t uiIg;		///<GND通道增益
	uint32_t uiVref;	///<基准电压
}CalibrationTPDF;		///<校准参数

/** 
 * @brief       获取校准数据
 * @param[out]  uiData (分别对应A、B、C小电流通道增益,A、B、C大通道、N、GND增益、基准值)
 * @retval      None
 */
extern void CalibrationGet(CalibrationTPDF *tCalibration);

/** 
 * @brief       保存校准数据
 * @param[in]   uiData (分别对应A、B、C小电流通道增益,A、B、C大通道、N、GND增益、基准值)
 * @retval      None
 */
extern void CalibrationSet(CalibrationTPDF *tCalibration);

/** 
 * @brief       获取通讯配置参数
* @retval       None
 */
extern void ComConfigGet(void);

/** 
 * @brief       保存通讯配置参数
* @retval       None
 */
extern void ComConfigSet(void);

/** 
 * @brief       获取用户配置
* @retval       None
 */
extern void CustomConfigGet(void);

/** 
 * @brief       保存用户配置
* @retval       None
 */
extern void CustomConfigSet(void);

/** 
 * @brief       恢复用户默认配置
 * @param[in]    bResetAll 是否默认所有参数
 * @retval       None
 */
extern void CustomConfigDefault(bool bResetAll);

/** 
 * @brief       获取工厂配置信息
 * @retval       None
 */
extern void FactoryConfigGet(void);

/** 
 * @brief       保存工厂配置信息
 * @retval       None
 */
extern void FactoryConfigSet(void);

/** 
 * @brief       设置安全配置
 * @retval      None
 */
extern void SecurityConfigSet(void);

/** 
 * @brief       获取安全配置
 * @retval      None
 */
extern void SecurityConfigGet(void);
#endif
